
'use strict'

const { Sequelize, DBPoolFile } = require('./mysqldb')

const FileInfo = function() {
  return DBPoolFile.define(
    'file_info',
    {
      file_id: {
        type: Sequelize.BIGINT,
        allowNull: false,
        defaultValue: 0
      },
      file_name: {
        type: Sequelize.STRING,
        allowNull: false,
        defaultValue: '',
        length: 255
      },
      uid: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0
      },
      image: {
        type: Sequelize.BLOB,
        allowNull: false
      },
      url: {
        type: Sequelize.STRING,
        allowNull: false,
        defaultValue: '',
        length: 1024
      },
      abstract: {
        type: Sequelize.STRING,
        allowNull: false,
        defaultValue: '',
        length: 1024
      },
      audit_status: {
        type: Sequelize.TINYINT,
        allowNull: false,
        defaultValue: 0
      },
      on: {
        type: Sequelize.BOOLEAN,
        allowNull: false,
        defaultValue: true
      }
    },
    {
      tableName: 'file_info',
      timestamps: true
    }
  )
}

const FileType = function() {
  return DBPoolFile.define(
    'file_type',
    {
      file_id: {
        type: Sequelize.BIGINT,
        allowNull: false,
        defaultValue: 0
      },
      sound_type: {
        type: Sequelize.INTEGER,
        allowNull: false,
        defaultValue: 0
      }
    },
    {
      tableName: 'file_type',
      timestamps: true
    }
  )
}

const FileAudit = function() {
  return DBPoolFile.define(
    'audit',
    {
      uid: {
        type: Sequelize.BIGINT,
        allowNull: false,
        defaultValue: 0
      },
      username: {
        type: Sequelize.STRING,
        allowNull: false,
        defaultValue: ''
      },
      file_id: {
        type: Sequelize.BIGINT,
        allowNull: false,
        defaultValue: 0
      },
      auditedAt: {
        type: Sequelize.DATE,
        allowNull: false,
        defaultValue: ''
      },
      auditor: {
        type: Sequelize.STRING,
        allowNull: false,
        defaultValue: ''
      },
      audit_status: {
        type: Sequelize.TINYINT,
        allowNull: false,
        defaultValue: 0
      },
      reason: {
        type: Sequelize.STRING,
        allowNull: false,
        defaultValue: '',
        length: 1024
      }
    },
    {
      tableName: 'audit',
      timestamps: true
    }
  )
}

const TableFileInfo = new FileInfo()
const TableFileType = new FileType()
const TableFileAudit = new FileAudit()

module.exports = {
  TableFileInfo,
  TableFileType,
  TableFileAudit
}
